﻿namespace SL651Center2.x.Enums
{
    /// <summary>
    /// 基本配置参数
    /// </summary>
    public enum BasicConfigCode : byte
    {
        /// <summary>
        /// 中心站地址
        /// </summary>
        BC_01 = 0x01,
        /// <summary>
        /// 遥测站地址
        /// </summary>
        BC_02 = 0x02,
        /// <summary>
        /// 密码
        /// </summary>
        BC_03 = 0x03,
        /// <summary>
        /// 中心站1主信道类型及地址
        /// </summary>
        BC_04 = 0x04,
        /// <summary>
        /// 中心站1备用信道类型及地址
        /// </summary>
        BC_05 = 0x05,
        /// <summary>
        /// 中心站2主信道类型及地址
        /// </summary>
        BC_06 = 0x06,
        /// <summary>
        /// 中心站2备用信道类型及地址
        /// </summary>
        BC_07 = 0x07,
        /// <summary>
        /// 中心站3主信道类型及地址
        /// </summary>
        BC_08 = 0x08,
        /// <summary>
        /// 中心站3备用信道类型及地址
        /// </summary>
        BC_09 = 0x09,
        /// <summary>
        /// 中心站4主信道类型及地址
        /// </summary>
        BC_0A = 0x0A,
        /// <summary>
        /// 中心站4备用信道类型及地址
        /// </summary>
        BC_0B = 0x0B,
        /// <summary>
        /// 工作方式
        /// </summary>
        BC_0C = 0x0C,
        /// <summary>
        /// 遥测站采集要素设置
        /// </summary>
        BC_0D = 0x0D,
        /// <summary>
        /// 中继站(集合转发站)服务地址范围
        /// </summary>
        BC_0E = 0x0E,
        /// <summary>
        /// 遥测站通信设备识别号
        /// </summary>
        BC_0F = 0x0F
    }

    /// <summary>
    /// 基本配置信息
    /// </summary>
    public class BasicConfigInfo
    {
        public static BasicConfigInfo Instance { get; } = new BasicConfigInfo();
        private Dictionary<BasicConfigCode, string> _basicConfigInfo = new Dictionary<BasicConfigCode, string>();
        private BasicConfigInfo()
        {
            Register(BasicConfigCode.BC_01, "中心站地址");
            Register(BasicConfigCode.BC_02, "遥测站地址");
            Register(BasicConfigCode.BC_03, "密码");
            Register(BasicConfigCode.BC_04, "中心站1主信道类型及地址");
            Register(BasicConfigCode.BC_05, "中心站1备用信道类型及地址");
            Register(BasicConfigCode.BC_06, "中心站2主信道类型及地址");
            Register(BasicConfigCode.BC_07, "中心站2备用信道类型及地址");
            Register(BasicConfigCode.BC_08, "中心站3主信道类型及地址");
            Register(BasicConfigCode.BC_09, "中心站3备用信道类型及地址");
            Register(BasicConfigCode.BC_0A, "中心站4主信道类型及地址");
            Register(BasicConfigCode.BC_0B, "中心站4备用信道类型及地址");
            Register(BasicConfigCode.BC_0C, "工作方式");
            Register(BasicConfigCode.BC_0D, "遥测站采集要素设置");
            Register(BasicConfigCode.BC_0E, "中继站(集合转发站)服务地址范围");
            Register(BasicConfigCode.BC_0F, "遥测站通信设备识别号");

        }
        private void Register(BasicConfigCode code, string name)
        {
            _basicConfigInfo[code] = name;
        }

        /// <summary>
        /// 获取基本要素的名称
        /// </summary>
        /// <param name="code">基本配置编码</param>
        /// <returns>基本配置的名称</returns>
        public string GetName(BasicConfigCode code)
        {
            if (_basicConfigInfo.TryGetValue(code, out var name))
            {
                return name;
            }
            return "";
        }

        /// <summary>
        /// 获取基本配置的数据字节长度和精度
        /// </summary>
        /// <param name="code">基本配置编码</param>
        /// <returns>数据的字节长度和编码</returns>
        public static (int d, decimal pre) GetValueType(BasicConfigCode code)
        {
            switch (code)
            {
                case BasicConfigCode.BC_01:
                    return (4, 1);
                case BasicConfigCode.BC_02:
                    return (5, 1);
                case BasicConfigCode.BC_03:
                    return (2, 1);
                case BasicConfigCode.BC_0C:
                    return (1, 1);
                case BasicConfigCode.BC_0D:
                    return (8, 1);
                default:
                    return (0, 1);
            }
        }

    }

}
